package org.tinygroup.sdpm.zhang.userController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tinygroup.sdpm.common.web.BaseController;
import org.tinygroup.sdpm.zhang.dao.inter.pojo.Goods;
import org.tinygroup.sdpm.zhang.dao.inter.pojo.Goodsorder;
import org.tinygroup.sdpm.zhang.dao.inter.pojo.User;
import org.tinygroup.sdpm.zhang.service.inter.GoodsOrderServiceInter;
import org.tinygroup.sdpm.zhang.service.inter.GoodsServiceInter;
import org.tinygroup.sdpm.zhang.service.inter.MyUserServiceInter;

import java.util.Date;
import java.util.UUID;

@RestController
@RequestMapping(value = "/myuser")
public class UserController extends BaseController {

    @Autowired
    private MyUserServiceInter myUserServiceInter;

    @Autowired
    private GoodsOrderServiceInter goodsOrderServiceInter;

    @Autowired
    private GoodsServiceInter goodsServiceInter;

    @RequestMapping("user/{pk}")
    public User getUser(@PathVariable String pk){
        return myUserServiceInter.getUserByKey(pk);
    }

    @RequestMapping("borrow/{user_id}/{goods_id}")
    public void brrow(@PathVariable String user_id,@PathVariable String goods_id){
        Goodsorder goodsorder=new Goodsorder();
        goodsorder.setUserId(user_id);
        goodsorder.setGoodsId(goods_id);
        goodsorder.setOrderId(UUID.randomUUID().toString());
        goodsorder.setOutTime(new Date());
        goodsOrderServiceInter.addGoodsOrder(goodsorder);
        Goods goods=new Goods();
        goods.setGoodsId(goods_id);
        goods.setJoinType("2");
        goodsServiceInter.editGoods(goods);
    }
}
